<?php
session_start();
//包含头
include '../PHP/head.php';
?>
<?php
//包含bootstrap的顶端按钮
include '../PHP/menu.php';
?>

<br />
<br />
<p class="text-center lead">底价表校核</p>
<?php

//接收操作
if (isset($_GET['files_id'])) {
	$files_id = $_GET['files_id'];
	$checked = $_GET['checked'];
	require_once ('../FNS/db_fns.php');
	$db = db_connect();
	//获取task_id
	
	$query="select task_id from files where id = '".$files_id."'";
	$result=$db->query ($query);
	$row=$result->fetch_assoc ();
	$task_id = stripslashes ($row['task_id']);
	$result->free();
	//获取当前状态
	$query="select status, project_id, subject from task_list where id = '".$task_id."'";
	$result=$db->query ($query);
	$row=$result->fetch_assoc ();
	$task_status = stripslashes ($row['status']);
	$project_id = stripslashes ($row['project_id']);
	$subject = stripslashes ($row['subject']);
	$result->free();
	
	$proposal_status = substr($task_status,1,1);
	
	//获取时间
	$check_date = date ('Y-m-d');
	
	if($checked == 'ok') {
		
		$task_status = "F".$proposal_status;
		//如果状态已达到'FF'，把完成时间打上
		if ($task_status == "FF") {
			$query="update task_list set status = '".$task_status."', finish_date = '".$check_date."' where id = '".$task_id."'";
			$query_p = "update projects set ".$subject."_flag = '5' where id = '".$project_id."'";
		} else {
			$query="update task_list set status = '".$task_status."' where id = '".$task_id."'";
			$query_p = "update projects set ".$subject."_flag = '3' where id = '".$project_id."'";
		}
		$result=$db->query ($query);
		$query="update files set checker = '".$user_id."', check_date = '".$check_date."', check_result = '通过' where id = '".$files_id."'";
		$result=$db->query ($query);
		$result=$db->query ($query_p);
		if ($result){
			echo "<br />";
			echo "<p>校核通过。</p>";
		}else{
			echo "<br />";
			echo"<p>校核失败！</p>";
	
		$db->close();
		}
	}
	if($checked == 'back') {
		$task_status = "M".$proposal_status;
		$query="update task_list set status = '".$task_status."' where id = '".$task_id."'";
		$result=$db->query ($query);
		$query="update files set checker = '".$user_id."', check_date = '".$check_date."', check_result = '退回' where id = '".$files_id."'";
		$result=$db->query ($query);
		if ($result){
			echo "<br />";
			echo "<p>已退回。</p>";
		}else{
			echo "<br />";
			echo"<p>退回失败！</p>";
	
		$db->close();
		}
	}
}


//从task_list中搜出status like "I%"、“subjecti”是自己专业的任务
require_once ('../FNS/db_fns.php');
//弄到专业号
$subject = substr ($user_position, 1, 2);
$subject = strtolower ($subject);


$db = db_connect();
$query="select task_list.id, projects.code as project_code, projects.name as project_name, users.name as issue_name from task_list 
	inner join projects on task_list.project_id = projects.id 
	inner join users on task_list.user_id = users.id 
	where task_list.status LIKE 'I%' and task_list.subject = '".$subject."' order by task_list.id";
$result=$db->query ($query);
if (!$result) {
	echo "<br />";
	echo "<p>没有未校核的底价表。</p>";
	echo "<p>subject是".$subject."</p>";
	echo "</div>";
	echo "</body>";
	$db->close();
exit;
}
$num_result=$result->num_rows;
//写表头
echo "<table class='table table-striped'>";
echo "<tr>";
	echo "<td align='center' class='info'><strong>报价编号</strong></td>";
	echo "<td align='center' class='info'><strong>项目名称</strong></td>";
	echo "<td align='center' class='info'><strong>提出人</strong></td>";
	echo "<td align='center' class='info'><strong>操作</strong></td>";
echo "</tr>";



//循环编制表格
for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$project_code = stripslashes ($row['project_code']);
	$project_name = stripslashes ($row['project_name']);
	$issue_name = stripslashes ($row['issue_name']);
	$task_id = stripslashes ($row['id']);
	
	$link_list = "../PHP/list_file_issue.php?task_id=".$task_id."&type=底价";
	
	echo "<tr>";
	echo "<td align ='center'>".$project_code."</td>";
	echo "<td align ='center'>".$project_name."</td>";
	echo "<td align ='center'>".$issue_name."</td>";
	echo "<td align='center'>
		<a class='btn btn-info btn-sm' href='".$link_list."' role='button'>文件列表</a>
		</td>";
	echo "</tr>";
	
}
echo "</table>";


$result->free();
$db->close();
?>




</div>
</body>
</html>